#include "DRListItemGroup.h"
#include "ui_DRListItemGroup.h"

DRListItemGroup::DRListItemGroup(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DRListItemGroup)
{
    ui->setupUi(this);

    ui->pushButton->hide();

    _index = -1;
    _deleteable = false;

    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
}

DRListItemGroup::DRListItemGroup(QString text, int index, bool deleteable, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::DRListItemGroup)
{
    ui->setupUi(this);

    ui->pushButton->hide();
    ui->label->setText(text);

    _deleteable = deleteable;
    _index = index;

    connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(deleteClicked()));
}

DRListItemGroup::~DRListItemGroup()
{
    delete ui;
}

int DRListItemGroup::index()
{
    return _index;
}

void DRListItemGroup::setIndex(int index)
{
    _index = index;
}

QString DRListItemGroup::text()
{
    return ui->label->text();
}

void DRListItemGroup::setText(QString text)
{
    ui->label->setText(text);
}

void DRListItemGroup::deleteClicked()
{
    emit onDelete(_index);
}

void DRListItemGroup::enterEvent(QEvent * event)
{
    if (_deleteable)
    {
        ui->pushButton->show();
    }
}

void DRListItemGroup::leaveEvent(QEvent * event)
{
    if (_deleteable)
    {
        ui->pushButton->hide();
    }
}
